<?php
include_once('../lib/Sqlexecutor.php');
include_once('../lib/Login.php');
include('log4php/Logger.php');

$dbh = new Sqlexecutor('localhost', 'tile', 'tile', 'tile');
Logger::configure('config.ini');
$logger = Logger::getLogger('intf');

$s = new Login($dbh, $logger);

$username = isset($_REQUEST['username']) ? $_REQUEST['username'] : '';
$password = isset($_REQUEST['password']) ? $_REQUEST['password'] : '';

if($username == '' || $password == '')
{
    $res['errno'] = -2; 
    $output = json_encode($res); 
    $logger->trace("input: username=$username, password=$password; res: $output"); 
    echo $output;
    exit;
}

$info = $s->login($username, $password);

$res = array();
if(is_array($info))
{
   $res = $info; 
   $res['errno'] = 0;
}
else
{
    $res['errno'] = $info;
}


$output = json_encode($res); 
$logger->trace("input: username=$username, password=$password; res: $output"); 
echo $output;
?>
